import logging
from redis import StrictRedis


class AppConfig(object):
    """flask配置类"""

    # 配置秘钥：项目中的CSRF和session需要用到，还有一些其他的签名算法也要用到
    SECRET_KEY = "gfohaegnrjaljiqo940@#$%^DGHUIL"
    DEBUG = True

    # mysql数据库配置
    SQLALCHEMY_DATABASE_URI = "mysql://root:mysql@127.0.0.1:3306/second_information"
    SQLALCHEMY_TRACK_MODIFICATIONS = False

    # Redis数据库配置
    REDIS_HOST = "127.0.0.1"
    REDIS_PORT = 6379

    # 将 session 数据保存到 Redis 中配置
    SESSION_TYPE = "redis"
    SESSION_REDIS = StrictRedis(REDIS_HOST, REDIS_PORT)
    # 是否将session签名后再存储
    SESSION_USE_SIGNER = True
    PERMANENT_SESSION_LIFETIME = 60*60*24 # 设置为1天


class DevelopmentConfig(AppConfig):
    """开发环境下的配置"""
    LEVEL_LOG = logging.DEBUG


class ProductionConfig(AppConfig):
    """生产环境下的配置"""
    LEVEL_LOG = logging.ERROR
    DEBUG = False
    SQLALCHEMY_DATABASE_URI = "mysql://root:mysql@127.0.0.1:3306/second_information"


class UnittestConfig(AppConfig):
    """测试环境下配置"""
    LEVEL_LOG = logging.DEBUG
    TESTING = True
    SQLALCHEMY_DATABASE_URI = "mysql://root:mysql@127.0.0.1:3306/second_information"


config_level = {
    "dev": DevelopmentConfig,
    "pro": ProductionConfig,
    "unit": UnittestConfig
}